<template>
  <div id="headerNav">
    <div id="logo">
      <img src="../assets/img/logo.png" />
    </div>
    <ul id="topNav">
      <li>
        <router-link to="/index">首页</router-link>
      </li>
      <li>
        <router-link to="/myDouban">我的豆瓣</router-link>
      </li>
    </ul>
    <div id="searchBox">
      <router-link to="/search">
        <img @click="search" src="../assets/img/search.png" />
      </router-link>

      <input
        type="text"
        class="searchInput"
        placeholder="搜索你感兴趣的内容"
        v-model="searchContent"
      />
    </div>
  </div>
</template>

<script>
import { Request } from "../until/request";
export default {
  name: "headerNav",

  data() {
    return {
      //搜索框的内容
      searchContent: ""
    };
  },
  mounted() {},
  methods: {
    search() {
      let key = this.searchContent;
      let req = new Request();
      req
        .send("get", `api/api/dynamicState/search/${key}`)
        .then(res => {
          if (res.data.code == 200) {
            this.searchContent = "";
            this.$emit("passData", res.data.data);
            sessionStorage.setItem("searchData", JSON.stringify(res.data.data));
            console.log(res.data);
          } else {
            this.searchContent = "";
            this.$emit("passData", null);
          }
        })
        .catch(err => {
          console.log(err);
        });
    }
  }
};
</script>

<style  scoped>
#headerNav {
  display: flex;
  align-items: center;
}
#logo {
  width: 20rem;
  /* background: yellow; */
}
#topNav {
  width: 30rem;
  display: flex;
  margin-right: auto;
}
#topNav li {
  width: 15rem;
  padding: 0.6rem 0;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 1.2rem;

  /* background: pink; */
}
#topNav li a {
  padding: 0.1rem;
  color: rgb(84, 86, 82);
}
#topNav li:hover a {
  background: rgb(84, 86, 82);
  color: white;
}

#logo img {
  width: 12rem;
  height: 2.5rem;
  cursor: pointer;
}
#searchBox img {
  width: 2rem;
  height: 2rem;
  position: absolute;
  right: 0;
  cursor: pointer;
}
#searchBox {
  /* background: lightcoral; */
  position: relative;
}
#searchBox input {
  width: 10rem;
  height: 1.5rem;
  padding: 0.1rem 0.5rem;
  border-radius: 0.7rem;
  border: 1px solid #cccccc;
  background: transparent;
}
</style>